
use "...\...\Austerity.dta"

xtset id year


**In order to compute the weighted version of each variable (prefix w in the dataset).

gen wgrowth=(trim-1)/4*growth + (5-trim)/4*l.growth
gen wdeltagrowth=(trim-1)/4*d.growth + (5-trim)/4*l.d.growth
gen wlgrowth=(trim-1)/4*l.growth + (5-trim)/4*l.l.growth


***********
* Article *
***********

*** Table 1

xtreg votesgov lagvotesgov wunemployment wgrowth coalition enep deltaturnout if crisis==0, re
xtreg votesgov lagvotesgov wunemployment wgrowth wdeltaadjprimbalance coalition enep deltaturnout if crisis==0, re
xtreg votesgov lagvotesgov wunemployment wgrowth coalition enep deltaturnout if crisis==1, re
xtreg votesgov lagvotesgov wunemployment wgrowth wdeltaadjprimbalance coalition enep deltaturnout if crisis==1, re


***Figure 1

*IMF
xtreg votesgov lagvotesgov wunemployment wgrowth c.wdeltaadjprimbalance##i.imf coalition enep deltaturnout if crisis==1, re
outreg2 using outputconditional.doc, label addstat(R-squared, `e(r2_o)') dec(2) replace
margins, dydx(wdeltaadjprimbalance) at(imf =(0(1)1)) vsquish
marginsplot, legend(off) scheme(s2mono) graphregion(fcolor(white)) xsca(titlegap(2)) ///
addplot(hist imf if crisis==1, percent yaxis(2) bin(20) lwidth(vvthin) color(none) lcolor(gs10) yscale(alt axis(2)))  ///
yline(0, lcolor(red)) ytitle("Marginal Effect of AUSTERITY", axis(1)) title("") xtitle(IMF conditionality) title("")

*Taxbase
xtreg votesgov lagvotesgov wunemployment wgrowth c.wdeltaadjprimbalance##c.taxbase coalition enep deltaturnout if crisis==1, re
outreg2 using outputconditional.doc, label addstat(R-squared, `e(r2_o)') dec(2) append
margins, dydx(wdeltaadjprimbalance) at(taxbase =(-8.5(0.25)17.5)) vsquish
marginsplot, recast (line) recastci(rline) ciopts(lpattern(dash)) ///
yline(0, lcolor(red)) ytitle("Marginal Effect of AUSTERITY", axis(1)) xsc(r(24 42)) title("") ///
addplot(hist taxbase if crisis==1, percent yaxis(2) bin(20) lwidth(vvthin) color(none) lcolor(gs10) yscale(alt axis(2))) ///
legend(off) scheme(s2mono) graphregion(fcolor(white)) xsca(titlegap(2)) ///
xtitle(EXPENDITURES vs TAXES) title("")

*Taxbase without outliers
xtreg votesgov lagvotesgov wunemployment wgrowth c.wdeltaadjprimbalance##c.taxbase coalition enep deltaturnout if crisis==1 & ctryear!="Ireland2011" & ctryear!="Estonia2011", re
margins, dydx(wdeltaadjprimbalance) at(taxbase =(-5.5(0.1)5.5)) vsquish
marginsplot, recast (line) recastci(rline) ciopts(lpattern(dash)) ///
yline(0, lcolor(red)) ytitle("Marginal Effect of AUSTERITY", axis(1)) xsc(r(24 42)) title("") ///
addplot(hist taxbase if crisis==1 & ctryear!="Ireland2011" & ctryear!="Estonia2011", percent yaxis(2) bin(20) lwidth(vvthin) color(none) lcolor(gs10) yscale(alt axis(2))) ///
legend(off) scheme(s2mono) graphregion(fcolor(white)) xsca(titlegap(2)) ///
xtitle(EXPENDITURES vs TAXES) title("")


*** For the multiple imputation produced by Amelia

*after mi set
*mi import flong, m(imp) id(year id) imp(wgini)
*after computing wgini

use "C:\..\Austerity amelia.dta"

*to check the association between conditional variables
mi estimate: regress wgini taxbase
mi estimate: regress wgini imf
mi estimate: regress taxbase imf


*model
mi estimate: xtreg votesgov lagvotesgov wunemployment wgrowth c.wdeltaadjprimbalance##c.wgini coalition enep deltaturnout if crisis==1, re
mimrgns, dydx(wdeltaadjprimbalance) at(wgini =(24(0.1)41)) vsquish
return list
matrix list r(table)

matrix A=r(table)
matrix list A
* transpose the matrix
matrix B=A'
matrix list B
clear
svmat B
rename B1 yhat
rename B2 se
rename B5 ll
rename B6 ul
keep yhat se ll ul

gen inequality = 23.9 +(_n/10)

save "C:\...\amelia-graph.dta", replace
append using "C:\...\amelia-final.dta"

save "C:\...\amelia all inclusive.dta", replace
		
twoway (line yhat inequality, lcolor(black) lwidth(thin)) ///
       (line ll inequality, lcolor(gs6) lwidth(thin) lpattern(dash)) ///
	   (line ul inequality, lcolor(gs6) lwidth(thin) lpattern(dash)), ///
	    ytitle(Marginal Effect of AUSTERITY) yscale (alt) yline(0, lcolor(red)) xtitle(INEQUALITY) ///
		legend(off) scheme(s2mono) graphregion(fcolor(white)) ysca(titlegap(2))|| hist wgini if crisis==1, ///
		yscale(alt) percent yaxis(2) bin(20) lwidth(vvthin) color(none) lcolor(gs10) 

graph save Graph "C:\...\amelia graph.gph", replace


*******************
* Online appendix *
*******************

use "...\...\Austerity.dta"

****** Descriptives statistics

*Table A.2
by crisis, sort : tabstat unemployment growth primbalance grossdebt if year>1999, statistics( mean) by(country)

*Table A.3
by crisis, sort: sum deltavotesgov wunemployment wdeltaunemployment wgrowth wprimbalance wgrossdebt wdeltaadjprimbalance deltaturnout enep wginiadjusted if wdeltaadjprimbalance!=.

*Figure A.1
twoway (scatter d.adjprimbalance year)

**dynamics of fiscal policy
by crisis, sort : tabstat deltaadjprimbalance if year>1999, statistics(sum) by(country)

*Table A.4
*Fixed effects
xtreg votesgov wunemployment wgrowth wdeltaadjprimbalance coalition enep deltaturnout if crisis==0, fe
xtreg votesgov wunemployment wgrowth wdeltaadjprimbalance coalition enep deltaturnout if crisis==1, fe

*Interactive research design
*Figure A.2
xtreg votesgov lagvotesgov c.wunemployment##c.crisis c.wgrowth##c.crisis c.wdeltaadjprimbalance##c.crisis coalition enep deltaturnout, re
margins, dydx(wunemployment) at(crisis =(0(1)1)) vsquish
marginsplot, legend(off) scheme(s2mono) graphregion(fcolor(white)) xsca(titlegap(2)) ///
addplot(hist crisis, percent yaxis(2) bin(15) lwidth(vvthin) color(none) lcolor(gs10) yscale(alt axis(2)))  ///
yline(0, lcolor(red)) ytitle("Marginal Effect of UNEMPLOYMENT", axis(1)) title("") xtitle("CRISIS")
margins, dydx(wgrowth) at(crisis =(0(1)1)) vsquish
marginsplot, legend(off) scheme(s2mono) graphregion(fcolor(white)) xsca(titlegap(2)) ///
addplot(hist crisis, percent yaxis(2) bin(15) lwidth(vvthin) color(none) lcolor(gs10) yscale(alt axis(2)))  ///
yline(0, lcolor(red)) ytitle("Marginal Effect of GROWTH", axis(1)) title("") xtitle("CRISIS")
margins, dydx(wdeltaadjprimbalance) at(crisis =(0(1)1)) vsquish
marginsplot, legend(off) scheme(s2mono) graphregion(fcolor(white)) xsca(titlegap(2)) ///
addplot(hist crisis, percent yaxis(2) bin(15) lwidth(vvthin) color(none) lcolor(gs10) yscale(alt axis(2)))  ///
yline(0, lcolor(red)) ytitle("Marginal Effect of AUSTERITY", axis(1)) title("") xtitle("CRISIS")


*Table A.5
*Trend instead of, and added to the level of unemployment
xtreg votesgov lagvotesgov wdeltaunemployment wgrowth wdeltaadjprimbalance coalition enep deltaturnout if crisis==0, re
xtreg votesgov lagvotesgov wunemployment wdeltaunemployment wgrowth wdeltaadjprimbalance coalition enep deltaturnout if crisis==0, re
xtreg votesgov lagvotesgov wdeltaunemployment wgrowth wdeltaadjprimbalance coalition enep deltaturnout if crisis==1, re
xtreg votesgov lagvotesgov wunemployment wdeltaunemployment wgrowth wdeltaadjprimbalance coalition enep deltaturnout if crisis==1, re

*Table A.7
*Expenditure cuts vs Tax increases
xtreg votesgov lagvotesgov wunemployment wgrowth wdeltaexpenditures coalition enep deltaturnout if crisis==1, re
xtreg votesgov lagvotesgov wunemployment wgrowth wdeltarevenues coalition enep deltaturnout if crisis==1, re
xtreg votesgov lagvotesgov wunemployment wgrowth wdeltaexpenditures wdeltarevenues coalition enep deltaturnout if crisis==1, re

*Table A.8 - Fig A.3
* Inequality with rough imputation of missings
xtreg votesgov lagvotesgov wunemployment wgrowth c.wdeltaadjprimbalance##c.wginiadjusted coalition enep deltaturnout if crisis==1, re
margins, dydx(wdeltaadjprimbalance) at(wginiadjusted =(24(0.5)41)) vsquish
marginsplot, recast (line) recastci(rline) ciopts(lpattern(dash)) ///
yline(0, lcolor(red)) ytitle("Marginal Effect of AUSTERITY", axis(1)) xsc(r(24 42)) title("") ///
addplot(hist wginiadjusted if crisis==1, percent yaxis(2) bin(20) lwidth(vvthin) color(none) lcolor(gs10) yscale(alt axis(2))) ///
legend(off) scheme(s2mono) graphregion(fcolor(white)) xsca(titlegap(2)) ///
xtitle(INEQUALITY) title("")



